﻿

@{
    ViewBag.Title = "未确认意向";
}


@*@model IEnumerable<MVC5Demo.Models.UserInfoViewModel>*@
@model System.Collections.IEnumerable

@*$("button").click(function(){
      $.post("demo_test_post.asp",
      {
        name:"Donald Duck",
        city:"Duckburg"
      },
      function(data,status){
        alert("Data: " + data + "\nStatus: " + status);
      });
    });*@

@*$("button").click(function(){
      $.get("demo_test.asp",function(data,status){
        alert("Data: " + data + "\nStatus: " + status);
      });
    });*@
@*$.ajax({
      type: 'POST',
      url: url,
      data: data,
      success: success,
      dataType: dataType
    });*@


<script src="~/Scripts/jquery-1.11.3.js"></script>
<script type="text/javascript">
    //$(document).ready(function () {
    //    alert("aaa")
    //});

    function postSugBtnClick(s, e) {
        //alert("1111111");
        //var mynums = new Array();
        //var i = 0;

        //alert(GridView2.cpCurrentPageSelectsRow().ToString());
        //for(var key in GridView2.GetCurrentPageRowValues("SugNum")) {
        //    if (GridView2.Selection.IsRowSelectedByKey(key))
        //        mynums[i] = GridView2.GetCurrentPageRowValues("SugNum");
        //}
        @*@functions {
            int GetFilteredRowCountWithoutPage(MVCxGridView grid) {
            int selectedRowsOnPage = 0;
            foreach(var key in grid.GetCurrentPageRowValues("CustomerID")) {
                if(grid.Selection.IsRowSelectedByKey(key))
                    selectedRowsOnPage++;
            }
            return grid.Selection.FilteredCount - selectedRowsOnPage;
            }
        }*@
        //alert(GridView2.cpCurrentPageSelectsRow);
        //var allcontent = yourArr.join("|");

        var allcontent = GridView.cpCurrentPageSelectsRow;
        if (allcontent.length > 0) {
                $.post("/Home/postCreateOrder",
           {
               sugnums: allcontent
           },

           function(data,status){
               //alert("Data: " + data + "\nStatus: " + status);
               var messages = data.split(":", 2)
               //alert(messages[0]);
               //alert(messages[1]);
               if (messages[0] == "error") {
                   alert(messages[1]);
                   window.location.href = "/Home/POSug";
               } else if (messages[0] == "success") {
                   alert(messages[1]);
                   //window.location.reload();//刷新当前页面.
                   window.location.href = "/Home/POSug";
               } else {

               } 
           }//null
           );
               // window.location.reload();//刷新当前页面.
        } else {
            alert("请选择数据");
        }
      
        //alert(allcontent);
        //s.GetSelectedFieldValues("ContactName", GetSelectedFieldValuesCallback);
       
    }

    // function OnGridViewInit(){
    //    var sug = GridView2.cpCurrentPageSelectsRow();
    //    alert("111");
    //}

    function OnGridViewSelectionChanged(s, e) {
        //var sug = GridView2.cpCurrentPageSelectsRow();
        //alert("111");
        s.GetSelectedFieldValues("SugNum;ReqNum;ReqLine", GetSelectedFieldValuesCallback);

        //alert(GridView2.cpCurrentPageSelectsRow().ToString());
        // alert("22");
    }
    function GetSelectedFieldValuesCallback(values) {
        // alert(values.length);
        //alert("22");

    }

    //  function OnGridViewEndCallback(){
    //      var sug = GridView2.cpCurrentPageSelectsRow();
    //    alert("333");
    //}

    //function getNewPOSugClick(s, e) {
    //    $.get("/Home/getNewPOSug",
    //        null);
    //    //$.get("www.baidu.com",function(data,status){
    //    //alert("Data: " + data + "\nStatus: " + status);
    //    //});
    //    //window.location.hash = "/Home/getNewPOSug";
    //    window.location.reload();//刷新当前页面.

    //    //或者下方刷新方法
    //    //parent.location.reload()刷新父亲对象（用于框架）--需在iframe框架内使用
    //    // opener.location.reload()刷新父窗口对象（用于单开窗口
    //    //top.location.reload()刷新最顶端对象（用于多开窗口）
    //    //alert("/Home/getNewPOSug");
    //}

    //function GetSelectedFieldValuesCallback(values) {
    //    SelectedRows.BeginUpdate();
    //    try {
    //        SelectedRows.ClearItems();
    //        for (var i = 0; i < values.length; i++) {
    //            SelectedRows.AddItem(values[i]);
    //        }
    //    } finally {
    //        SelectedRows.EndUpdate();
    //    }
    //    $("#count").html(gvRowSelection.GetSelectedRowCount());


    //}


    function OnClick(s, e) {
        var actionParams = $("form").attr("action").split("?filterString=");
        actionParams[1] = GridView.cpGridFilterExpression;
        $("form").attr("action", actionParams.join("?filterString="));
    }
        function UpdateGridHeight() {
            GridView.SetHeight(0);
            var containerHeight = ASPxClientUtils.GetDocumentClientHeight();
            if (document.body.scrollHeight > containerHeight)
                containerHeight = document.body.scrollHeight;
            GridView.SetHeight(containerHeight-150);
            //alert(containerHeight-150);
        }

        window.addEventListener('resize', function(evt) {
            if(!ASPxClientUtils.androidPlatform)
                return;
            var activeElement = document.activeElement;
            if(activeElement && (activeElement.tagName === "INPUT" || activeElement.tagName === "TEXTAREA") && activeElement.scrollIntoViewIfNeeded)
                window.setTimeout(function() { activeElement.scrollIntoViewIfNeeded(); }, 0);
        });

</script>

@*@Html.ActionLink("刷新","getNewPOSug", "Home");*@
<div>
    <table> <tr><td>
@using (Html.BeginForm(new { Controller = "Home", Action = "ExportToPOs" }))
{
    @Html.DevExpress().Button(settings =>
{
    settings.Name = "btnExport";
    settings.Text = "导出表格";
    settings.ClientSideEvents.Click = "OnClick";
    settings.UseSubmitBehavior = true;
}).GetHtml()}
        </td>
        
        <td>

            @Html.DevExpress().Button(settings =>
{
    settings.Name = "postSugBtn";
    settings.Text = "创建订单";
    settings.ClientSideEvents.Click = "postSugBtnClick";
    settings.UseSubmitBehavior = true;
}).GetHtml()
        </td></tr></table>
   
        @*@Html.DevExpress().Button(settings =>
{
    settings.Name = "getNewPOSug";
    settings.Text = "刷新";
    settings.ClientSideEvents.Click = "getNewPOSugClick";
    settings.UseSubmitBehavior = true;
}).GetHtml()*@
    

    
    @*<p style="color:red">@ViewBag.ErrorMessage</p>
    *@
</div>


<div>
    @Html.Partial("_POSugPartial", Model)
</div>

<script type="text/javascript">
        ASPxClientControl.GetControlCollection().ControlsInitialized.AddHandler(function (s, e) {
            UpdateGridHeight();
        });
        ASPxClientControl.GetControlCollection().BrowserWindowResized.AddHandler(function (s, e) {
            UpdateGridHeight();
        });
</script>